<template>
  <el-dialog title="操作记录" :visible.sync="visible" width="1000px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="操作类型" prop="operType">
        <el-select v-model="queryParams.operType" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.dis_operate_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="操作状态" prop="operState">
        <el-select v-model="queryParams.operState" placeholder="请选择" clearable size="small">
          <el-option v-for="dict in dict.type.iot_operate_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-table @row-click="clickRow" ref="table" :data="logList" @selection-change="handleSelectionChange" height="260px">
        <el-table-column label="编号" align="center" prop="hgId" />
        <el-table-column label="控制卡号" align="center" prop="boxNo" />
        <el-table-column prop="operType" label="操作类型" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.dis_operate_type" :value="scope.row.operType"/>
          </template>
        </el-table-column>
        <el-table-column prop="operState" label="操作状态" align="center" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.iot_operate_status" :value="scope.row.operState"/>
          </template>
        </el-table-column>
        <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
        <el-table-column label="操作时间" align="center" prop="createTime" width="157">
          <template slot-scope="scope">{{scope.row.createTime}}</template>
        </el-table-column>
        <el-table-column label="操作者" align="center" prop="createBy" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="handleSelectUser">确 定</el-button> -->
      <el-button @click="visible = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {listLog} from '@/api/iot/hgboxlog'
export default {
  dicts: ['dis_operate_type','iot_operate_status'],
  /* props: {
    // 角色编号
    roleId: {
      type: [Number, String]
    }
  }, */
  data() {
    return {
      visible: false,
      userIds: [],
      total: 0,
      logList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        boxNo: null,
        operType: null,
        operState: null,
      }
    };
  },
  methods: {
    show(boxNo) {
      this.queryParams.boxNo = boxNo;
      this.getList();
      this.visible = true;
    },
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    handleSelectionChange(selection) {
      this.userIds = selection.map(item => item.userId);
    },
    getList() {
      listLog(this.queryParams).then(res => {
        this.logList = res.rows;
        this.total = res.total;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
